package chapter06;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 * 容器的基本使用
 */
public class TestContainer {
    public static void main(String[] args) {
        // ArrayList
        testArrayList();

        // HashSet
        testHashSet();

        // HashMap
        testHashMap();
    }

    private static void testHashMap() {
        System.out.println("-----------------------testHashMap-------------------");
        HashMap<Integer, String> hashMap = new HashMap<>();

        hashMap.put(1, "张三");
        hashMap.put(2, "李四");
        hashMap.put(3, "王五");
        System.out.println(hashMap);

        System.out.println("hashMap.get(2)" + hashMap.get(2));
        System.out.println("hashMap.remove(2)" + hashMap.remove(2));
        System.out.println(hashMap);
    }

    private static void testHashSet() {
        System.out.println("-----------------------testHashSet-------------------");

        HashSet<Integer> hashSet = new HashSet<>();
        hashSet.add(1);
        hashSet.add(2);
        hashSet.add(3);
        hashSet.add(3);
        System.out.println(hashSet);

        System.out.println("hashSet.remove(2): " + hashSet.remove(2));
        System.out.println(hashSet);

    }

    private static void testArrayList() {
        System.out.println("-----------------------testArrayList-------------------");
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        System.out.println(arrayList);

        System.out.println("arrayList.get(1)： " + arrayList.get(1));

        System.out.println("arrayList.remove(1): " + arrayList.remove(1));

        System.out.println(arrayList);

    }
}
